package cn.itsub.boot.service.impl;

import cn.itsub.boot.mapper.CategoryMapper;
import cn.itsub.boot.model.Category;
import cn.itsub.boot.model.CategoryExample;
import cn.itsub.boot.service.CategoryService;
import com.alibaba.fastjson2.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Service
public class CategoryServiceImpl implements CategoryService{

    @Autowired
    CategoryMapper categoryMapper;

    @Override
    public List<Category> findByParentId(Integer pid) {
        List<Category> list = categoryMapper.selectByPid(pid);
        for (Category category : list) {
            List<Category> children = findByParentId(category.getId());
            category.setChildren(children);
        }
        System.out.println(JSON.toJSONString(list));
        return list;
    }
}
